package face.pay.web.advert.controller;


import face.pay.entity.AdvertBatch;
import face.pay.entity.AdvertMaterial;
import face.pay.entity.UserInfo;
import face.pay.security.annotation.CurrentUser;
import face.pay.util.ResultMessage;
import face.pay.util.page.PageData;
import face.pay.util.page.PageParam;
import face.pay.web.advert.service.IAdvertService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

@Controller
@RequestMapping("/advert")
public class AdvertController {


    @Autowired
    private IAdvertService iAdvertService;


    @RequestMapping("index")
    public String AdIndxe() {
        return "advertisement/ad_index";
    }


    @RequestMapping("batchlList")
    public String batchlList() {
        return "advertisement/ad_batch_list";
    }

    /**
     * 文件上传
     *
     * @param file
     * @param loginUser
     * @return
     */
    @RequestMapping("/fielUpload")
    @ResponseBody
    public ResultMessage fielUpload(@RequestParam("file") MultipartFile file, @CurrentUser UserInfo loginUser, String ad_type, String ad_title) throws Exception {
        byte[] fileBytes = file.getBytes();
        String originalFilename = file.getOriginalFilename();
        return this.iAdvertService.fielUpload(fileBytes, originalFilename, loginUser, ad_type, ad_title);
    }


    /**
     * 分页查询广告列表
     *
     * @param loginUser
     * @return
     */
    @RequestMapping("/queryAdList")
    @ResponseBody
    public PageData queryAdList(@CurrentUser UserInfo loginUser, AdvertMaterial advertMaterial, PageParam pageParam) {
        return this.iAdvertService.queryAdList(pageParam, loginUser, advertMaterial);
    }


    /**
     * 分页查询当前oem商下的设备列表
     *
     * @param loginUser
     * @return
     */
    @RequestMapping("/queryTerminalList")
    @ResponseBody
    public PageData queryTerminalList(@CurrentUser UserInfo loginUser, PageParam pageParam) {
        return this.iAdvertService.queryTerminalList(pageParam, loginUser);
    }


    /**
     * 新增一个广告批次
     *
     * @param loginUser
     * @return
     */
    @RequestMapping("/insertAdvertBatch")
    @ResponseBody
    public ResultMessage saveAdvertBatch(@CurrentUser UserInfo loginUser, AdvertBatch advertBatch) {
        return this.iAdvertService.insertAdvertBatch(loginUser, advertBatch);
    }


    /**
     * 配置广告
     *
     * @param loginUser
     * @return
     */
    @RequestMapping("/updatAd")
    @ResponseBody
    public ResultMessage updatAdvert(@CurrentUser UserInfo loginUser, AdvertBatch advertBatch, String adList) {
        return this.iAdvertService.updatAdvert(loginUser, advertBatch, adList);
    }


    /**
     * 配置设备
     *
     * @param loginUser
     * @return
     */
    @RequestMapping("/updatTerminal")
    @ResponseBody
    public ResultMessage updatTerminal(@CurrentUser UserInfo loginUser, AdvertBatch advertBatch, String terList) {
        return this.iAdvertService.updatTerminal(loginUser, advertBatch, terList);
    }

    /**
     * 分页查询当前oem商下的广告批次列表
     *
     * @param loginUser
     * @return
     */
    @RequestMapping("/queryAdvertBatchlList")
    @ResponseBody
    public PageData queryAdvertBatchlList(@CurrentUser UserInfo loginUser, PageParam pageParam, AdvertBatch advertBatch) {
        return this.iAdvertService.queryAdvertBatchlList(pageParam, loginUser, advertBatch);
    }

    /**
     * 查询广告详情
     *
     * @param loginUser
     * @return
     */
    @RequestMapping("/queryBatchlinfo")
    @ResponseBody
    public ResultMessage queryBatchlinfo(@CurrentUser UserInfo loginUser, Integer batchId) {
        return this.iAdvertService.queryBatchlinfo(loginUser, batchId);
    }


    /**
     * 推送广告
     *
     * @param loginUser
     * @return
     */
    @RequestMapping("/adPush")
    @ResponseBody
    public ResultMessage adPush(@CurrentUser UserInfo loginUser, Integer batchId) {
        return this.iAdvertService.adPush(loginUser, batchId);
    }


}
